package com.tansun.easycare.rule.datamodel.entity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.hibernate.validator.constraints.Length;

import com.tansun.easycare.rule.common.entity.RuleBaseEntity;
import com.tansun.ruledata.data.entity.DeployDataparams;
import com.tansun.ruledata.data.entity.DeployDataset;

/**
 * 规则数据集Entity
 *
 * @author lxs
 * @version 2017-02-17
 */
public class RuleDataset extends RuleBaseEntity<RuleDataset> {

    private static final long serialVersionUID = 1L;
    private String projectcode;        // 规则库编码
    private String name;        // 数据集名
    private String chzn;        // 中文名
    private String paramType;        // 类型（输入，输出，输入与输出，仅复用）
    private String dataDesc;        // 描述信息
    private String isbuiltin;       //是否内置变量 1：是
    private String paramChzn;
    private String paramName;
    private String deleteflag; //删除的标记
    private String datamodelid;  //关联数据模型id

	public DeployDataset changeClass(){
		DeployDataset newinfo = new DeployDataset();
		newinfo.setChzn(chzn);
		newinfo.setDataDesc(dataDesc);
		if(this.fieldMap!=null && this.fieldMap.isEmpty()) {
			Map<String, DeployDataparams> fieldMap = new HashMap<String, DeployDataparams>();
			for(String key:this.fieldMap.keySet()) {
				fieldMap.put(key, this.fieldMap.get(key).changeClass());
			}
			newinfo.setFieldMap(fieldMap);
		}
		newinfo.setId(id);
		newinfo.setmFieldNames(mFieldNames);
		newinfo.setName(name);
		newinfo.setParamChzn(paramChzn);
		newinfo.setParamType(paramType);
		newinfo.setProjectcode(projectcode);
		return newinfo;
	}
	
    public String getDatamodelid() {
		return datamodelid;
	}

	public void setDatamodelid(String datamodelid) {
		this.datamodelid = datamodelid;
	}

	@Override
	public String toString() {
		return "RuleDataset [projectcode=" + projectcode + ", name=" + name + ", chzn=" + chzn + ", paramType="
				+ paramType + ", dataDesc=" + dataDesc + ", paramChzn=" + paramChzn + ", deleteflag=" + deleteflag
				+ ", mFieldNames=" + mFieldNames + ", fieldMap=" + fieldMap +",datamodelid=" +datamodelid + "]";
	}

	public String getDeleteflag() {
		return deleteflag;
	}

	public void setDeleteflag(String deleteflag) {
		this.deleteflag = deleteflag;
	}

	private List<String> mFieldNames = new ArrayList<String>();
    private Map<String, RuleDataparams> fieldMap = new HashMap<String, RuleDataparams>();

    public RuleDataset() {
        super();
    }

    public RuleDataset(String id) {
        super(id);
    }

    @Length(min = 0, max = 50, message = "规则库编码长度必须介于 0 和 50 之间")
    public String getProjectcode() {
        return projectcode;
    }

    public void setProjectcode(String projectcode) {
        this.projectcode = projectcode;
    }

    @Length(min = 0, max = 30, message = "数据集名长度必须介于 0 和 30 之间")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Length(min = 0, max = 150, message = "中文名长度必须介于 0 和 150 之间")
    public String getChzn() {
        return chzn;
    }

    public void setChzn(String chzn) {
        this.chzn = chzn;
    }

    @Length(min = 0, max = 10, message = "类型（输入，输出，输入与输出，仅复用）长度必须介于 0 和 10 之间")
    public String getParamType() {
        return paramType;
    }

    public void setParamType(String paramType) {
        this.paramType = paramType;
    }

    @Length(min = 0, max = 100, message = "描述信息长度必须介于 0 和 100 之间")
    public String getDataDesc() {
        return dataDesc;
    }

    public void setDataDesc(String dataDesc) {
        this.dataDesc = dataDesc;
    }

    public List<String> getmFieldNames() {
        return mFieldNames;
    }

    public void setmFieldNames(List<String> mFieldNames) {
        this.mFieldNames = mFieldNames;
    }

    public Map<String, RuleDataparams> getFieldMap() {
        return fieldMap;
    }

    public void setFieldMap(Map<String, RuleDataparams> fieldMap) {
        this.fieldMap = fieldMap;
    }

    public String getParamChzn() {
        return paramChzn;
    }

    public void setParamChzn(String paramChzn) {
        this.paramChzn = paramChzn;
    }
    
//	public String getSql() {
//		return "INSERT INTO rule_dataset(id,projectcode,name,chzn,param_type,data_desc,create_date,data_version) values (?,?,?,?,?,?,?,?)";
//	}
//	public Object[] getArgs(String timeStamp) {
//		return new Object[] {this.id,this.projectcode,this.name,this.chzn,this.paramType,this.dataDesc,new Date(),timeStamp};
//	}
	
	public String getIsbuiltin() {
		return isbuiltin;
	}

	public String getParamName() {
		return paramName;
	}

	public void setParamName(String paramName) {
		this.paramName = paramName;
	}

	public void setIsbuiltin(String isbuiltin) {
		this.isbuiltin = isbuiltin;
	}

	public String getSql() {
		return "INSERT INTO rule_dataset(id,projectcode,name,chzn,param_type,data_desc,create_date,data_version) values ";
	}
	public String getArgs(String timeStamp) {
		return "('"+this.id+"','"
				+isEmpty(this.projectcode)+"','"
				+isEmpty(this.name)+"','"
				+isEmpty(this.chzn)+"','"
				+isEmpty(this.paramType)+"','"
				+isEmpty(this.dataDesc)+"',@currDate,'"
				+timeStamp
				+"')";
//		return new Object[] {this.id,this.projectcode,this.name,this.chzn,this.paramType,this.dataDesc,new Date(),timeStamp};
	}
	public String getArgs(String timeStamp,String currDate) {
		return "('"+this.id+"','"
				+isEmpty(this.projectcode)+"','"
				+isEmpty(this.name)+"','"
				+isEmpty(this.chzn)+"','"
				+isEmpty(this.paramType)+"','"
				+isEmpty(this.dataDesc)+"','"+currDate+"','"
				+timeStamp
				+"')";
//		return new Object[] {this.id,this.projectcode,this.name,this.chzn,this.paramType,this.dataDesc,new Date(),timeStamp};
	}
	public RuleDataset(String projectcode, String name, String chzn, String paramType, String dataDesc,
			String paramChzn, String deleteflag, List<String> mFieldNames, Map<String, RuleDataparams> fieldMap, String datamodelid) {
		super();
		this.projectcode = projectcode;
		this.name = name;
		this.chzn = chzn;
		this.paramType = paramType;
		this.dataDesc = dataDesc;
		this.paramChzn = paramChzn;
		this.deleteflag = deleteflag;
		this.mFieldNames = mFieldNames;
		this.fieldMap = fieldMap;
		this.datamodelid = datamodelid;
	}


}